---
title: LED Driver
---

# LED Driver

You can start a driver for WS2812B, APA102, or SK9822 using `startLed`.

```ts
import { LedVariant, LedStripLightType } from "@devicescript/core"
import { startLed } from "@devicescript/drivers"
import { pins } from "@dsboard/adafruit_qt_py_c3"

// highlight-start
const led = await startLed({
    length: 32,
    variant: LedVariant.Ring,
    hwConfig: { type: LedStripLightType.WS2812B_GRB, pin: pins.A0_D0 },
})
// highlight-end
```

## Gamma correction

The Led supports [Gamma correction](https://cdn-learn.adafruit.com/downloads/pdf/led-tricks-gamma-correction.pdf),
but it is disabled by default. Gamma correction is applied before rendering the colors
to account for how our eyes sense the light created by LEDs.

```ts skip
const led = await startLed({
    // highlight-next-line
    gamma: 2.8,
})
```

## Topology

You can specify the topology of the LED strip by using the `variant` register. The default is a flexible strip
but other popular options like `ring` are also available.

```ts skip
// highlight-next-line
import { LedVariant } from "@devicescript/core"

const led = await startLed({
    // highlight-next-line
    variant: LedVariant.Ring,
})
```

For LED `matrix` with row major, you should also specify the number of columns.

```ts skip
// highlight-next-line
import { LedVariant } from "@devicescript/core"

const led = await startLed({
    length: 64 // 8x8
    // highlight-next-line
    variant: LedVariant.Matrix,
    // highlight-next-line
    columns: 8
})
```

To work on the LEDs as it if was an image, use the [startLedDisplay](./display) helper.

## Maximum power consumption

A large number of LED consuming maximum power can lead to an impressive surge of
power consumption. The LED driver allows to specify a maximum power (in watts)
and a LED power consumption model. Given those information

```ts skip
const led = await startLed({
    maxPower: 5, // watts
})
```
